home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 4 #9 / IMG 40 Sep 1996.iso / More Goodies / More for Your Game / Sprite Fight 2002 / J52 SF2002 tools / SpriteFight2002⁄Tools#1 / SpriteFlipNMask.c < prev   
C/C++ Source or Header  |  1996-06-01  |  20KB  |  726 lines

  1. //• SpriteFlipNMask.c
  2. //• Copyright (c) 1996 by Stefan C. Sinclair
  3. //• All Rights Reserved Worldwide
  4. //• Flips the PICTs & then creates the Mask PICTs
  5.  
  6. #include <EPPC.h>
  7. #include <GestaltEqu.h>
  8. #include <AppleEvents.h>
  9. #include <Movies.h>
  10. #include <ctype.h>
  11. #include <Sound.h>
  12. #include <Dialogs.h>
  13.  
  14. #define kGestaltMask        1L
  15.  
  16. #define    kErrorAlertID                    128
  17. #define kMinTextPosition    0
  18. #define kMaxTextPosition    32767
  19.  
  20. #define kFirstLifePICT            128
  21. #define kNumLifePICT            43
  22. #define kFirstProjectilePICT    214
  23. #define kNumProjectilePICT        2
  24. #define kFirstDeathPICT            218
  25. #define kNumDeathPICT            10
  26. #define kRideChairPICT            238
  27. #define kSitChairPICT            240
  28. #define kMaskOffset                200
  29.  
  30. void InitToolbox(void);
  31. void AEInstallHandlers(void);
  32. pascal OSErr DoOpenApp( AppleEvent *event, AppleEvent *reply, long refcon);
  33. pascal OSErr DoOpenDoc( AppleEvent *event, AppleEvent *reply, long refcon);
  34. pascal OSErr DoPrintDoc( AppleEvent *event, AppleEvent *reply, long refcon);
  35. pascal OSErr DoQuitApp( AppleEvent *event, AppleEvent *reply, long refcon);
  36. OSErr CheckForRequiredParams( AppleEvent *event);
  37. void AEInit(void);
  38. void  MoviesInit( void );
  39. void  Open_A_Movie( void );
  40. void  Close_A_Movie( void );
  41. void DoError (char desc[255], short OScode, short myRef, Boolean fatal);
  42. void pStrCopy (StringPtr p1, StringPtr p2);
  43. pascal Boolean SpriteGuyFileFilter(fileParam *thePB );
  44. void  Handle_One_Event( void );
  45.  
  46. Boolean    All_Done = FALSE;
  47. EventRecord      The_Event;
  48.  
  49. main()
  50. {
  51.     InitToolbox();
  52.     MoviesInit();
  53.     AEInit();
  54.     
  55.     while ( All_Done == false )
  56.       Handle_One_Event();
  57.       
  58.     DoError("Ha! No errors! Apparently, it worked.", 0, 0, FALSE);
  59.  
  60.     return 0;
  61. }
  62.  
  63. void  Handle_One_Event( void )
  64. {        
  65.    WindowPtr  which_window;
  66.    long       movie_related_event;
  67.       
  68.    WaitNextEvent(everyEvent, &The_Event, 0, nil);
  69.     switch (The_Event.what)
  70.      {
  71.          case keyDown:
  72.          case autoKey:
  73.             break;
  74.          case updateEvt:
  75.             break;
  76.          case mouseDown:
  77.              Open_A_Movie();  
  78.             break;
  79.          case kHighLevelEvent:
  80.             AEProcessAppleEvent(&The_Event);
  81.             break;
  82.    }
  83. }
  84.  
  85. void InitToolbox()
  86. {
  87.     InitGraf((Ptr) &qd.thePort);
  88.     InitFonts();
  89.     InitWindows();
  90.     InitMenus();
  91.     FlushEvents(everyEvent,0);
  92.     TEInit();
  93.     InitDialogs(0L);
  94.     InitCursor();
  95. }
  96.  
  97. void  MoviesInit( void )
  98. {
  99.    OSErr  error;
  100.    long   result;
  101.     
  102.    error = Gestalt( gestaltQuickTime, &result );
  103.    if ( error != noErr )
  104.       DoError("Sorry, but you need QuickTime™ installed for this program to work.",0,0,TRUE);
  105.                                              
  106.    error = EnterMovies();  
  107.    if ( error != noErr )
  108.       DoError("Sorry, but you need QuickTime™ installed for this program to work.",0,0,TRUE); 
  109. }
  110.  
  111. void AEInit( void)
  112. {
  113.     OSErr    err;
  114.     long    feature;
  115.     
  116.     err = Gestalt(gestaltAppleEventsAttr, &feature);
  117.     if(err != noErr)
  118.         DoError("Error returned by gestalt!",0,0, true);
  119.     if(!(feature & (kGestaltMask << gestaltAppleEventsPresent)))
  120.         DoError("Apple Events not supported!",0,0, true);
  121.     AEInstallHandlers();
  122. }
  123.  
  124. void AEInstallHandlers(void)
  125. {
  126.     OSErr    err;
  127.     /* install the required apple event handlers */
  128.     AEEventHandlerUPP OPENae, QUITae, STARTae, PRINTae;
  129.     
  130.     /* must use these for PPC proc pointers */
  131.     OPENae = NewAEEventHandlerProc ((ProcPtr) &DoOpenDoc);
  132.     QUITae = NewAEEventHandlerProc ((ProcPtr) &DoQuitApp);
  133.     STARTae = NewAEEventHandlerProc ((ProcPtr) &DoOpenApp);
  134.     PRINTae = NewAEEventHandlerProc ((ProcPtr) &DoPrintDoc);
  135.     err = AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,STARTae, 0L, false);
  136.     if(err != noErr)
  137.         DoError("Error installing 'open app' handler!",0,0, true);
  138.     err = err = AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments, OPENae, 0L, false);
  139.     if(err != noErr)
  140.         DoError("Error installing 'open doc' handler!",0,0, true);
  141.     err = err = AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments, PRINTae, 0L, false);
  142.     if(err != noErr)
  143.         DoError("Error installing 'print doc' handler!",0,0, true);
  144.     err = err = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, QUITae, 0L, false);
  145.     if(err != noErr)
  146.         DoError("Error installing 'quit app' handler!",0,0, true);
  147. }
  148.  
  149. pascal OSErr DoOpenApp( AppleEvent *event, AppleEvent *reply, long refcon)
  150. {
  151.     Open_A_Movie();
  152.     return noErr;
  153. }
  154.  
  155. pascal OSErr DoOpenDoc( AppleEvent *event, AppleEvent *reply, long refcon)
  156. {
  157.     OSErr        err;
  158.     FSSpec        fileSpec;
  159.     long        i, numDocs;
  160.     DescType    returnedType;
  161.     AEKeyword    keywd;
  162.     Size        actualSize;
  163.     AEDescList    docList = {typeNull, nil};    // Get the direct parameter-a descriptor list-and put into docList
  164.     
  165.     err = AEGetParamDesc(event, keyDirectObject, typeAEList, &docList);
  166.     err = CheckForRequiredParams( event);    // Check for missing required parameters
  167.     if(err)
  168.     {
  169.         err = AEDisposeDesc( &docList);
  170.         return err;
  171.     }
  172.     err = AECountItems( &docList, &numDocs);    // Count #of descriptor records in the list
  173.     if(err)                                    // Should be at least 1 since we got called & no error.
  174.     {
  175.         err = AEDisposeDesc( &docList);
  176.         return err;
  177.     }
  178.     // Now get each descriptor record, coerce data to an FSSpec record, & open the file
  179.     //for( i = 1; i <= numDocs; i++)
  180.     //{
  181.         err = AEGetNthPtr( &docList, 1, typeFSS, &keywd, &returnedType, (Ptr)&fileSpec, sizeof(fileSpec), &actualSize);
  182.         Open_A_Movie();
  183.     //}
  184.     err = AEDisposeDesc( &docList);
  185.     return err;
  186. }
  187.  
  188.  
  189. OSErr CheckForRequiredParams( AppleEvent *appleEventPtr)
  190. {
  191.     DescType        returnedType;
  192.     Size            actualSize;
  193.     OSErr            err;
  194.     
  195.     err = AEGetAttributePtr( appleEventPtr, keyMissedKeywordAttr, typeWildCard, &returnedType, nil, 0, &actualSize);
  196.     //• Looks for specified attribute, returns attribute status as an error
  197.     
  198.     if( err == errAEDescNotFound)
  199.         return noErr;
  200.     else if( err == noErr)
  201.         return errAEParamMissed;
  202.     else
  203.         return err;
  204. }
  205.  
  206. pascal OSErr DoPrintDoc( AppleEvent *event, AppleEvent *reply, long refcon)
  207. {
  208.     return noErr;
  209. }
  210.  
  211. pascal OSErr DoQuitApp( AppleEvent *event, AppleEvent *reply, long refcon)
  212. {
  213.     All_Done = true;
  214.     return noErr;
  215. }
  216.  
  217. void  Open_A_Movie( void )
  218. {  
  219.    SFTypeList         type_list = { MovieFileType,'MYqt', 0, 0 };
  220.    StandardFileReply  the_reply;
  221.    Str255             movie_name;
  222.    Boolean            was_changed;
  223.    FileFilterUPP      myFileFilter;
  224.    short            curResRefNum, i, j, k, x, y;
  225.    Rect                r128, rWind, rPICT;
  226.    CWindowPtr        aWindow;
  227.    OSErr            err;
  228.    BitMap            bmp;
  229.    PicHandle        spritePICT, flipPICT, maskPICT, flipMaskPICT;
  230.    Rect    r;
  231.     RGBColor    c, b = {0,0,0}, w = {65535, 65535, 65535};
  232.    
  233.        myFileFilter = NewFileFilterProc(SpriteGuyFileFilter);
  234.       StandardGetFilePreview( myFileFilter, -1/*numTypes*/, type_list, &the_reply );
  235.        if( the_reply.sfGood != true )
  236.            ExitToShell();
  237.        else
  238.       {          
  239.            curResRefNum = HOpenResFile(the_reply.sfFile.vRefNum,
  240.                 the_reply.sfFile.parID,the_reply.sfFile.name,
  241.                 fsRdWrPerm);
  242.         err = ((ResError()!=noErr) || (curResRefNum < 0));
  243.         
  244.         if (err != noErr)
  245.             DoError("Error opening resource fork!",err,0,TRUE);
  246.         else
  247.         {    
  248.             r128.top = r128.left = 0;
  249.             r128.bottom = r128.right = 128;
  250.             rWind.top = rWind.left = 60;
  251.             rWind.bottom = 220;
  252.             rWind.right = 400;
  253.             rPICT.top = 0; rPICT.left = 130;
  254.             rPICT.right = rPICT.left + 128;
  255.             rPICT.bottom = 128;
  256.             
  257.             aWindow = (CWindowPtr)NewCWindow(nil, &rWind, "\pFlip 'n Mask",
  258.                     TRUE, documentProc, (WindowPtr)-1L, TRUE, 0);
  259.             SetPort((GrafPtr)aWindow);
  260.             ShowWindow((WindowPtr)aWindow);
  261.             ValidRect(&aWindow->portRect);
  262.             
  263.             UseResFile(curResRefNum);
  264.             
  265.             ForeColor(blackColor);
  266.             BackColor(whiteColor);
  267.  
  268.             for(i=kFirstLifePICT; i<(kFirstLifePICT+kNumLifePICT); i++)
  269.             {
  270.                   ClipRect(&qd.thePort->portRect);
  271.                   EraseRect(&qd.thePort->portRect);
  272.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  273.                 if(spritePICT == NULL)
  274.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  275.                 HLock((Handle)spritePICT);
  276.                 DrawPicture(spritePICT, &r128);
  277.                 // flip it
  278.                 for(j=0; j<128; j++)
  279.                 {
  280.                     for(k=0; k<128; k++)
  281.                     {
  282.                         GetCPixel(j, k, &c);
  283.                         x = rPICT.right - j;
  284.                         SetCPixel(x, k, &c);
  285.                             
  286.                     }
  287.                 }
  288.                 flipPICT = OpenPicture(&rPICT);
  289.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  290.                     &rPICT, &rPICT, srcOr, nil);
  291.                 ClosePicture();
  292.                 AddResource((Handle)flipPICT, 'PICT', (i+kNumLifePICT), "\p");
  293.                 if(ResError())
  294.                 {
  295.                     DoError("ResError!",i,ResError(),TRUE);
  296.                 }
  297.                 WriteResource((Handle)flipPICT);
  298.                 
  299.                 // mask the original
  300.                 for(j=0; j<128; j++)
  301.                 {
  302.                     for(k=0; k<128; k++)
  303.                     {
  304.                         GetCPixel(j, k, &c);
  305.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  306.                             ;
  307.                         else
  308.                             SetCPixel(j, k, &b); // not white, so make it black
  309.                     }
  310.                 }
  311.                 maskPICT = OpenPicture(&r128);
  312.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  313.                     &r128, &r128, srcOr, nil);
  314.                 ClosePicture();
  315.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  316.                 if(ResError())
  317.                 {
  318.                     DoError("ResError!",i,ResError(),TRUE);
  319.                 }
  320.                 WriteResource((Handle)maskPICT);
  321.                 
  322.                 // flip the mask now
  323.                 for(j=0; j<128; j++)
  324.                 {
  325.                     for(k=0; k<128; k++)
  326.                     {
  327.                         GetCPixel(j, k, &c);
  328.                         x = rPICT.right - j;
  329.                         SetCPixel(x, k, &c);
  330.                             
  331.                     }
  332.                 }
  333.                 flipMaskPICT = OpenPicture(&rPICT);
  334.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  335.                     &rPICT, &rPICT, srcOr, nil);
  336.                 ClosePicture();
  337.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+kNumLifePICT+kMaskOffset), "\p");
  338.                 if(ResError())
  339.                 {
  340.                     DoError("ResError!",i,ResError(),TRUE);
  341.                 }
  342.                 WriteResource((Handle)flipMaskPICT);
  343.                 
  344.                 // dispose of all PICTs
  345.                 ReleaseResource((Handle)spritePICT);
  346.                 ReleaseResource((Handle)maskPICT);
  347.                 ReleaseResource((Handle)flipMaskPICT);
  348.                 ReleaseResource((Handle)flipPICT);
  349.                 
  350.                 EraseRect(&qd.thePort->portRect);
  351.             }
  352.             
  353.             for(i=kFirstProjectilePICT; i<(kFirstProjectilePICT+kNumProjectilePICT); i++)
  354.             {
  355.                   ClipRect(&qd.thePort->portRect);
  356.                   EraseRect(&qd.thePort->portRect);
  357.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  358.                 if(spritePICT == NULL)
  359.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  360.                 HLock((Handle)spritePICT);
  361.                 DrawPicture(spritePICT, &r128);
  362.                 // flip it
  363.                 for(j=0; j<128; j++)
  364.                 {
  365.                     for(k=0; k<128; k++)
  366.                     {
  367.                         GetCPixel(j, k, &c);
  368.                         x = rPICT.right - j;
  369.                         SetCPixel(x, k, &c);
  370.                             
  371.                     }
  372.                 }
  373.                 flipPICT = OpenPicture(&rPICT);
  374.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  375.                     &rPICT, &rPICT, srcOr, nil);
  376.                 ClosePicture();
  377.                 AddResource((Handle)flipPICT, 'PICT', (i+kNumProjectilePICT), "\p");
  378.                 if(ResError())
  379.                 {
  380.                     DoError("ResError!",i,ResError(),TRUE);
  381.                 }
  382.                 WriteResource((Handle)flipPICT);
  383.                 
  384.                 // mask the original
  385.                 for(j=0; j<128; j++)
  386.                 {
  387.                     for(k=0; k<128; k++)
  388.                     {
  389.                         GetCPixel(j, k, &c);
  390.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  391.                             ;
  392.                         else
  393.                             SetCPixel(j, k, &b); // not white, so make it black
  394.                     }
  395.                 }
  396.                 maskPICT = OpenPicture(&r128);
  397.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  398.                     &r128, &r128, srcOr, nil);
  399.                 ClosePicture();
  400.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  401.                 if(ResError())
  402.                 {
  403.                     DoError("ResError!",i,ResError(),TRUE);
  404.                 }
  405.                 WriteResource((Handle)maskPICT);
  406.                 
  407.                 // flip the mask now
  408.                 for(j=0; j<128; j++)
  409.                 {
  410.                     for(k=0; k<128; k++)
  411.                     {
  412.                         GetCPixel(j, k, &c);
  413.                         x = rPICT.right - j;
  414.                         SetCPixel(x, k, &c);
  415.                             
  416.                     }
  417.                 }
  418.                 flipMaskPICT = OpenPicture(&rPICT);
  419.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  420.                     &rPICT, &rPICT, srcOr, nil);
  421.                 ClosePicture();
  422.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+kNumProjectilePICT+kMaskOffset), "\p");
  423.                 if(ResError())
  424.                 {
  425.                     DoError("ResError!",i,ResError(),TRUE);
  426.                 }
  427.                 WriteResource((Handle)flipMaskPICT);
  428.                 
  429.                 // dispose of all PICTs
  430.                 ReleaseResource((Handle)spritePICT);
  431.                 ReleaseResource((Handle)maskPICT);
  432.                 ReleaseResource((Handle)flipMaskPICT);
  433.                 ReleaseResource((Handle)flipPICT);
  434.                 
  435.                 EraseRect(&qd.thePort->portRect);
  436.             }
  437.  
  438.             for(i=kFirstDeathPICT; i<(kFirstDeathPICT+kNumDeathPICT); i++)
  439.             {
  440.                   ClipRect(&qd.thePort->portRect);
  441.                   EraseRect(&qd.thePort->portRect);
  442.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  443.                 if(spritePICT == NULL)
  444.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  445.                 HLock((Handle)spritePICT);
  446.                 DrawPicture(spritePICT, &r128);
  447.                 // flip it
  448.                 for(j=0; j<128; j++)
  449.                 {
  450.                     for(k=0; k<128; k++)
  451.                     {
  452.                         GetCPixel(j, k, &c);
  453.                         x = rPICT.right - j;
  454.                         SetCPixel(x, k, &c);
  455.                             
  456.                     }
  457.                 }
  458.                 flipPICT = OpenPicture(&rPICT);
  459.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  460.                     &rPICT, &rPICT, srcOr, nil);
  461.                 ClosePicture();
  462.                 AddResource((Handle)flipPICT, 'PICT', (i+kNumDeathPICT), "\p");
  463.                 if(ResError())
  464.                 {
  465.                     DoError("ResError!",i,ResError(),TRUE);
  466.                 }
  467.                 WriteResource((Handle)flipPICT);
  468.                 
  469.                 // mask the original
  470.                 for(j=0; j<128; j++)
  471.                 {
  472.                     for(k=0; k<128; k++)
  473.                     {
  474.                         GetCPixel(j, k, &c);
  475.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  476.                             ;
  477.                         else
  478.                             SetCPixel(j, k, &b); // not white, so make it black
  479.                     }
  480.                 }
  481.                 maskPICT = OpenPicture(&r128);
  482.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  483.                     &r128, &r128, srcOr, nil);
  484.                 ClosePicture();
  485.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  486.                 if(ResError())
  487.                 {
  488.                     DoError("ResError!",i,ResError(),TRUE);
  489.                 }
  490.                 WriteResource((Handle)maskPICT);
  491.                 
  492.                 // flip the mask now
  493.                 for(j=0; j<128; j++)
  494.                 {
  495.                     for(k=0; k<128; k++)
  496.                     {
  497.                         GetCPixel(j, k, &c);
  498.                         x = rPICT.right - j;
  499.                         SetCPixel(x, k, &c);
  500.                             
  501.                     }
  502.                 }
  503.                 flipMaskPICT = OpenPicture(&rPICT);
  504.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  505.                     &rPICT, &rPICT, srcOr, nil);
  506.                 ClosePicture();
  507.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+kNumDeathPICT+kMaskOffset), "\p");
  508.                 if(ResError())
  509.                 {
  510.                     DoError("ResError!",i,ResError(),TRUE);
  511.                 }
  512.                 WriteResource((Handle)flipMaskPICT);
  513.                 
  514.                 // dispose of all PICTs
  515.                 ReleaseResource((Handle)spritePICT);
  516.                 ReleaseResource((Handle)maskPICT);
  517.                 ReleaseResource((Handle)flipMaskPICT);
  518.                 ReleaseResource((Handle)flipPICT);
  519.                 
  520.                 EraseRect(&qd.thePort->portRect);
  521.             }
  522.             
  523.             for(i=kRideChairPICT; i<(kRideChairPICT+1); i++)
  524.             {
  525.                   ClipRect(&qd.thePort->portRect);
  526.                   EraseRect(&qd.thePort->portRect);
  527.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  528.                 if(spritePICT == NULL)
  529.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  530.                 HLock((Handle)spritePICT);
  531.                 DrawPicture(spritePICT, &r128);
  532.                 // flip it
  533.                 for(j=0; j<128; j++)
  534.                 {
  535.                     for(k=0; k<128; k++)
  536.                     {
  537.                         GetCPixel(j, k, &c);
  538.                         x = rPICT.right - j;
  539.                         SetCPixel(x, k, &c);
  540.                             
  541.                     }
  542.                 }
  543.                 flipPICT = OpenPicture(&rPICT);
  544.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  545.                     &rPICT, &rPICT, srcOr, nil);
  546.                 ClosePicture();
  547.                 AddResource((Handle)flipPICT, 'PICT', (i+1), "\p");
  548.                 if(ResError())
  549.                 {
  550.                     DoError("ResError!",i,ResError(),TRUE);
  551.                 }
  552.                 WriteResource((Handle)flipPICT);
  553.                 
  554.                 // mask the original
  555.                 for(j=0; j<128; j++)
  556.                 {
  557.                     for(k=0; k<128; k++)
  558.                     {
  559.                         GetCPixel(j, k, &c);
  560.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  561.                             ;
  562.                         else
  563.                             SetCPixel(j, k, &b); // not white, so make it black
  564.                     }
  565.                 }
  566.                 maskPICT = OpenPicture(&r128);
  567.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  568.                     &r128, &r128, srcOr, nil);
  569.                 ClosePicture();
  570.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  571.                 if(ResError())
  572.                 {
  573.                     DoError("ResError!",i,ResError(),TRUE);
  574.                 }
  575.                 WriteResource((Handle)maskPICT);
  576.                 
  577.                 // flip the mask now
  578.                 for(j=0; j<128; j++)
  579.                 {
  580.                     for(k=0; k<128; k++)
  581.                     {
  582.                         GetCPixel(j, k, &c);
  583.                         x = rPICT.right - j;
  584.                         SetCPixel(x, k, &c);
  585.                             
  586.                     }
  587.                 }
  588.                 flipMaskPICT = OpenPicture(&rPICT);
  589.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  590.                     &rPICT, &rPICT, srcOr, nil);
  591.                 ClosePicture();
  592.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+1+kMaskOffset), "\p");
  593.                 if(ResError())
  594.                 {
  595.                     DoError("ResError!",i,ResError(),TRUE);
  596.                 }
  597.                 WriteResource((Handle)flipMaskPICT);
  598.                 
  599.                 // dispose of all PICTs
  600.                 ReleaseResource((Handle)spritePICT);
  601.                 ReleaseResource((Handle)maskPICT);
  602.                 ReleaseResource((Handle)flipMaskPICT);
  603.                 ReleaseResource((Handle)flipPICT);
  604.                 
  605.                 EraseRect(&qd.thePort->portRect);
  606.             }
  607.             
  608.             for(i=kSitChairPICT; i<(kSitChairPICT+1); i++)
  609.             {
  610.                   ClipRect(&qd.thePort->portRect);
  611.                   EraseRect(&qd.thePort->portRect);
  612.                 spritePICT = (PicHandle)Get1Resource('PICT', i);
  613.                 if(spritePICT == NULL)
  614.                     DoError("File is missing a PICT resource!",i,0,TRUE);
  615.                 HLock((Handle)spritePICT);
  616.                 DrawPicture(spritePICT, &r128);
  617.                 // flip it
  618.                 for(j=0; j<128; j++)
  619.                 {
  620.                     for(k=0; k<128; k++)
  621.                     {
  622.                         GetCPixel(j, k, &c);
  623.                         x = rPICT.right - j;
  624.                         SetCPixel(x, k, &c);
  625.                             
  626.                     }
  627.                 }
  628.                 flipPICT = OpenPicture(&rPICT);
  629.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  630.                     &rPICT, &rPICT, srcOr, nil);
  631.                 ClosePicture();
  632.                 AddResource((Handle)flipPICT, 'PICT', (i+1), "\p");
  633.                 if(ResError())
  634.                 {
  635.                     DoError("ResError!",i,ResError(),TRUE);
  636.                 }
  637.                 WriteResource((Handle)flipPICT);
  638.                 
  639.                 // mask the original
  640.                 for(j=0; j<128; j++)
  641.                 {
  642.                     for(k=0; k<128; k++)
  643.                     {
  644.                         GetCPixel(j, k, &c);
  645.                         if(c.red == w.red && c.blue == w.blue && c.green == w.green)
  646.                             ;
  647.                         else
  648.                             SetCPixel(j, k, &b); // not white, so make it black
  649.                     }
  650.                 }
  651.                 maskPICT = OpenPicture(&r128);
  652.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  653.                     &r128, &r128, srcOr, nil);
  654.                 ClosePicture();
  655.                 AddResource((Handle)maskPICT, 'PICT', (i+kMaskOffset), "\p");
  656.                 if(ResError())
  657.                 {
  658.                     DoError("ResError!",i,ResError(),TRUE);
  659.                 }
  660.                 WriteResource((Handle)maskPICT);
  661.                 
  662.                 // flip the mask now
  663.                 for(j=0; j<128; j++)
  664.                 {
  665.                     for(k=0; k<128; k++)
  666.                     {
  667.                         GetCPixel(j, k, &c);
  668.                         x = rPICT.right - j;
  669.                         SetCPixel(x, k, &c);
  670.                             
  671.                     }
  672.                 }
  673.                 flipMaskPICT = OpenPicture(&rPICT);
  674.                 CopyBits(&qd.thePort->portBits,&qd.thePort->portBits,
  675.                     &rPICT, &rPICT, srcOr, nil);
  676.                 ClosePicture();
  677.                 AddResource((Handle)flipMaskPICT, 'PICT', (i+1+kMaskOffset), "\p");
  678.                 if(ResError())
  679.                 {
  680.                     DoError("ResError!",i,ResError(),TRUE);
  681.                 }
  682.                 WriteResource((Handle)flipMaskPICT);
  683.                 
  684.                 // dispose of all PICTs
  685.                 ReleaseResource((Handle)spritePICT);
  686.                 ReleaseResource((Handle)maskPICT);
  687.                 ReleaseResource((Handle)flipMaskPICT);
  688.                 ReleaseResource((Handle)flipPICT);
  689.                 
  690.                 EraseRect(&qd.thePort->portRect);
  691.             }
  692.             
  693.             CloseResFile(curResRefNum);
  694.             All_Done = TRUE;
  695.         } 
  696.        }
  697.        All_Done = TRUE;
  698. }
  699.  
  700. //************************************************************************
  701. void DoError (char desc[255], short OScode, short myRef, Boolean fatal)
  702. {
  703.     /* A fatal error has occurred - report it and quit */
  704.     short go;
  705.     Str63    a, b;
  706.     
  707.     c2pstr(desc);
  708.     NumToString (OScode, a);
  709.     NumToString (myRef, b);
  710.     ParamText ((StringPtr)desc, a, b, NULL);
  711.     NoteAlert(kErrorAlertID,NULL);
  712.     if(fatal)
  713.         ExitToShell();
  714. }
  715.  
  716. /* This filters out (discards) non-sprite files. It will also let QuickTime movie
  717. files slip by - no reason why, I just did it that way! */
  718. pascal Boolean SpriteGuyFileFilter(fileParam *thePB )
  719. {
  720.     if (thePB->ioFlFndrInfo.fdType=='Ned2')
  721.         return(FALSE);        /* SF2K2 file, keep it in the list */
  722.     else if ( thePB->ioFlFndrInfo.fdType == MovieFileType )
  723.         return(FALSE);        /* movie file, keep it in the list */
  724.     else
  725.         return(TRUE);            /* Nope, filter it from the list */
  726. }